/*
<Copyright (C) 2011 Dru Moore>

This file is part of demorecorder.

vlc-remote is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

demorecorder is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with demorecorder.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DEMORECORDER_H
#define DEMORECORDER_H

#include <QObject>
#include <QString>
#include <QStringList>
#include <QTimer>
#include <QAbstractListModel>
#include <QDeclarativeContext>
#include "mixerpipeline.h"
#include "playpipeline.h"
#include "recordpipeline.h"
#include "composition.h"
#include "simpletrack.h"
#include "tracklistmodel.h"
#include <gst/gst.h>

class DemoRecorder : public QObject
{
    Q_OBJECT
public:
    explicit DemoRecorder(QObject *parent = 0);
    DemoRecorder(QObject *parent = 0, QDeclarativeContext *context = NULL);
    Q_INVOKABLE void play();
    Q_INVOKABLE void pause();
    Q_INVOKABLE void rewind();
    Q_INVOKABLE void advance();
    Q_INVOKABLE void record();
    Q_INVOKABLE void stop();
    Q_INVOKABLE void stoprecording();
    Q_INVOKABLE void setProjectFolder(const QString &path);

    Q_INVOKABLE void trackToggleActive(const int idx, bool active);
    Q_INVOKABLE void trackToggleMute(const int idx, bool mute);
    Q_INVOKABLE void trackSetVolume(const int idx, double volume);
    Q_INVOKABLE void trackSetPanorama(const int idx, double panorama);

    Q_INVOKABLE QString getMyString(const QString &text) const;
    Q_INVOKABLE long getPlayheadPosition() const;
    Q_INVOKABLE long getPlayheadDuration() const;
    Q_INVOKABLE long getRecorderPosition() const;

signals:
    void playbackEnded();
    void playbackError();
    void recordingEnded();
    void recordingError();
    void pipelineReady();

public slots:
    void createPipeline();
    void createRecordPipeline();
    void teardownRecordPipeline();
    void eos_handler();
    void position_duration_handler(long long position, long long duration);
    void recorder_eos_handler();
    void recorder_position_duration_handler(long long position, long long duration);

private:
    QTimer *timer;
    QTimer *recorder_timer;
    MixerPipeline *pipeline;
    //PlayPipeline *pipeline;
    RecordPipeline *recordpipeline;
    Composition *composition;
    QString projectFolderPath;
    QString current_file;
    QStringList tracks;
    long long playhead_position;
    long long playhead_duration;
    long long recorder_position;
    long long recorder_duration;
    QDeclarativeContext *context;
    TrackListModel trackListModel;
    QList<SimpleTrack*> simpletracks;
    void loadProjectTracks();


};

#endif // DEMORECORDER_H
